package university.dropcourse.service;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.jws.WebService;
import javax.persistence.EntityExistsException;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import university.dropcourse.conversion.DocenteConv;
import university.dropcourse.conversion.StudenteConv;
import university.dropcourse.dto.DocenteDto;
import university.dropcourse.dto.StudenteDto;
import university.dropcourse.entity.Docente;
import university.dropcourse.entity.Studente;

/**
 * Session Bean implementation class RegistrationManager
 */
@Stateless
@LocalBean
@WebService
public class RegistrationManagerBean {
	
	@PersistenceContext
	private EntityManager manager;	
	@EJB
    DocenteConv docConv;
	@EJB
	StudenteConv studConv;
	
    public RegistrationManagerBean() {   }
    
    public void registraDocente(DocenteDto d) throws EntityExistsException {
    	
    	Docente doc = docConv.fromDto(d);
    	manager.persist(doc); 
    	manager.flush();
    	
    }
    
    public void registraStudente(StudenteDto s) throws EntityExistsException {
    	
    	Studente stud = studConv.fromDto(s);
    	manager.persist(stud); 
    	manager.flush();
    	
    }

}
